package cn.lili.controller.promotion;

import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.GreenContributionInfo;
import cn.lili.modules.promotion.entity.vos.GreenContributionInfoVO;
import cn.lili.modules.promotion.entity.vos.GreenContributionInfoViewVO;
import cn.lili.modules.promotion.entity.vos.GreenPointStatistic;
import cn.lili.modules.promotion.service.GreenContributionInfoService;
import cn.lili.modules.promotion.service.GreenCountService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pojos.GOrder;
import com.pojos.GmoneyResUser;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xiangqian
 * @version 1.0
 * @data 2023/12/18 18:48
 * <p>
 * 绿色积分池-贡献值详情
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/promotion/green/contribution/info")
public class GreenContributionInfoController {

    private final GreenContributionInfoService greenContributionInfoService;
    private final GreenCountService greenCountService;

    /**
     * 分页查询贡献值明细
     *
     * @param greenContributionInfo 查询条件{@link GreenContributionInfo}
     * @param page                  分页条件{@link PageVO}
     * @return 分页返回结果
     */
    @GetMapping("/page")
    public ResultMessage<Page<GreenContributionInfo>> infoPage(GreenContributionInfo greenContributionInfo, PageVO page) {
        return ResultUtil.data(greenContributionInfoService.infoPage(greenContributionInfo, page));
    }

    /**
     * 分页查询绿色积分(绿色积分管理-用户)
     *
     * @param gmoneyResUser 查询条件{@link GmoneyResUser}
     * @param page          分页条件{@link PageVO}
     * @return 分页返回结果
     */
    @ApiModelProperty("")
    @GetMapping("/green/page")
    public ResultMessage<Page<GmoneyResUser>> greenPage(GmoneyResUser gmoneyResUser, PageVO page) {
        return ResultUtil.data(greenContributionInfoService.greenPage(gmoneyResUser, page));
    }

    /**
     * 绿色积分明细(绿色积分管理-用户)
     *
     * @param gOrder 查询条件{@link GOrder}
     * @param page   分页条件{@link PageVO}
     * @return 分页返回结果
     */
    @GetMapping("/green/info")
    public ResultMessage<Page<GOrder>> getGreenInfo(GOrder gOrder, PageVO page) {
        return ResultUtil.data(greenCountService.getGreenInfo(gOrder, page));
    }

    /**
     * 冻结/解冻绿色积分(绿色积分管理-用户)
     *
     * @param openId  用户openId
     * @param payType 冻结状态 0 解冻， 1 只允许进不允许出， 2 进出都不允许，直接禁用
     * @return 冻结结果
     */
    @ApiModelProperty("冻结/解冻绿色积分")
    @GetMapping("/green/freeze")
    public ResultMessage<JSONObject> greenFreeze(String openId, Integer payType) {
        return ResultUtil.data(greenCountService.greenFreeze(openId, payType));
    }

    @ApiOperation("绿色贡献值记录查询/绿色贡献值兑换记录")
    @GetMapping("/getUnionContributeDetails")
    public ResultMessage<Page<GreenContributionInfoViewVO>> getUnionContributeDetails(GreenContributionInfo info, PageVO page) {
        return ResultUtil.data(greenContributionInfoService.getUnionContributeDetails(info, page));
    }

    @ApiOperation("绿色积分和绿色贡献值统计")
    @GetMapping("/statisticsGreenUnsettle")
    public ResultMessage<GreenPointStatistic> greenPointStatisticUnsettle(GreenContributionInfo info) {
        return greenContributionInfoService.greenPointStatisticUnsettle(info);
    }


}
